/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Jayson Kiong
 */
public class UpdateTermServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        Connection con = DBConnector.connect();
       
        
        try{
        int termid = Integer.parseInt(request.getParameter("termid"));
        int term = Integer.parseInt(request.getParameter("term"));
        String clienttype = request.getParameter("clienttype");
        String loantype = request.getParameter("loantype");
        String subtype = request.getParameter("subtype");
        float lessui = Float.parseFloat(request.getParameter("lessui"));
        float servicecharge = Float.parseFloat(request.getParameter("servicecharge"));
        float notaryfee = Float.parseFloat(request.getParameter("notaryfee"));
        float evat = Float.parseFloat(request.getParameter("evat"));
        float docs = Float.parseFloat(request.getParameter("docs"));
        float collectionfee = Float.parseFloat(request.getParameter("collectionfee"));
        float processingfee = Float.parseFloat(request.getParameter("processingfee"));
        float lbccharge = Float.parseFloat(request.getParameter("lbccharge"));
        float cashbound = Float.parseFloat(request.getParameter("cashbound"));
        float commission = Float.parseFloat(request.getParameter("commission"));
        float bankcharge = Float.parseFloat(request.getParameter("bankcharge"));
        
        PreparedStatement ps = con.prepareStatement
            ("UPDATE quicklenddb.terms SET terms = ?, clienttype=?, loantype=?, subtype=?,less_ui=?/100,service_charge=?/100,notary_fee=?/100,evat=?/100,docs=?/100,collectionfee=?/100,processingfee=?/100,bank_charge=?,lbc_charge=?,cashbound=?,commission=? where termID=?");
                
                
                ps.setInt(1, term);
                ps.setString(2, clienttype);
                ps.setString(3, loantype);
                ps.setString(4, subtype);
                ps.setFloat(5, lessui);
                ps.setFloat(6, servicecharge);
                ps.setFloat(7, notaryfee);
                ps.setFloat(8, evat);
                ps.setFloat(9, docs);
                ps.setFloat(10, collectionfee);
                ps.setFloat(11, processingfee);
                ps.setFloat(12, bankcharge);
                ps.setFloat(13, lbccharge);
                ps.setFloat(14, cashbound);
                ps.setFloat(15, commission);
                ps.setInt(16, termid);
             
                
                ps.executeUpdate();
                
               
                response.sendRedirect("TermServlet");
            
            
        }catch(SQLException e)
        {
            System.out.println(e); 
            //Logger.getLogger(RegisterServlet.class.getName()).log(Level.SEVERE, null, e);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
